<template>
  <div
    v-if="currentItem"
    :style="$bgImage(currentItem.img)"
    class="com-web-me-video w-image-fit"
    @mouseleave="videoMouseleave"
  >
    <video
      :src="currentItem.video"
      class="video"
      autoplay
      loop
      controls="controls"
    >
      您的浏览器不支持 video 标签。
    </video>
    <div :style="{ right: listShow ? '0' : '-200px' }" class="video-list-box">
      <div class="video-list">
        <div
          v-for="(v, index) in videos"
          :key="`${v.video}_${index}`"
          :style="$bgImage(v.img)"
          class="item w-image-fit w-pointer"
          @click="videoImgClick(v)"
        />
      </div>
      <div
        class="state-box w-flex-center w-pointer"
        @click="listShow = !listShow"
      >
        <a-icon :type="listShow ? 'double-right' : 'double-left'" class="other-icon"/>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
import { Video } from '@/models/video'

@Component({
  name: 'ComWebMeVideo'
})
export default class ComWebMeViewo extends Vue {
  @Prop({ default: () => [] }) videos!: Array<Video>

  listShow = false
  currentItem: Video | null = null

  created () {
    const length = this.videos.length
    const index = Math.floor(Math.random() * length)
    this.currentItem = this.videos[index]
  }

  videoImgClick (item: Video) {
    this.currentItem = item
  }

  videoMouseleave () {
    this.listShow = false
  }
}
</script>

<style scoped lang="less">
.com-web-me-video {
  overflow: hidden;
  position: relative;
  height: 708.75px;
  .video {
    width: 100%;
    height: 100%;
  }
  .video:focus {
    outline: 0;
  }
  .video-list-box {
    position: absolute;
    right: -200px;
    top: 0px;
    width: 200px;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    transition: all 0.5s;
    .video-list {
      height: 100%;
      overflow: auto;
      .item {
        width: 100%;
        height: 100px;
      }
    }
    .state-box {
      position: absolute;
      width: 20px;
      height: 80px;
      background-color: rgba(0, 0, 0, 0.5);
      left: -20px;
      top: 50%;
      opacity: 0;
      margin-top: -40px;
      border-radius: 20px 0 0 20px;
      transition: all 0.5s;
    }
  }
  .other-icon {
    color: #fff;
    font-size: 16px;
  }
}
.com-web-me-video:hover {
  .state-box {
    opacity: 1;
  }
}
</style>
